package com.yike.user.service.impl;

import com.yike.user.entity.CategoryCount;
import com.yike.user.mapper.CategoryCountMapper;
import com.yike.user.service.CategoryCountService;
import com.yike.user.param.CategoryCountPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 商品分类统计 服务实现类
 *
 * @author Sakura
 * @since 2024-11-19
 */
@Slf4j
@Service
public class CategoryCountServiceImpl extends BaseServiceImpl<CategoryCountMapper, CategoryCount> implements CategoryCountService {

    @Autowired
    private CategoryCountMapper categoryCountMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveCategoryCount(CategoryCount categoryCount) throws Exception {
        return super.save(categoryCount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCategoryCount(CategoryCount categoryCount) throws Exception {
        return super.updateById(categoryCount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteCategoryCount(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<CategoryCount> getCategoryCountPageList(CategoryCountPageParam categoryCountPageParam) throws Exception {
        Page<CategoryCount> page = new PageInfo<>(categoryCountPageParam, OrderItem.desc(getLambdaColumn(CategoryCount::getCreateTime)));
        LambdaQueryWrapper<CategoryCount> wrapper = new LambdaQueryWrapper<>();
        IPage<CategoryCount> iPage = categoryCountMapper.selectPage(page, wrapper);
        return new Paging<CategoryCount>(iPage);
    }

}
